/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2023-03-05
 * Time: 18:37
 */
class MyCircularQueue {

    private int[] elem;
    private int front;//表示队列的头
    private int rear;//表示队列的尾
    //private int usedSize;表示队列的元素个数
    //构造
    public MyCircularQueue(int k) {
        //如果是舍弃一个空间进行判读是否队列已满的模拟，在测试中如果需要存放k个元素，那么应该开辟k+1个元素。this.elem = new int[k + 1];
        this.elem = new int[k];
    }

    //入队列
    public boolean enQueue(int value) {
        //1.检查是否队列是满的
        if(isFull()) {
            return false;
        }
        //2.
        elem[rear] = value;
        rear = (rear + 1) % elem.length;
        return true;
    }

    //出队列
    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        //直接将front向前移动一位，因为后续我们就会直接进行覆盖
        front = (front + 1) % elem.length;
        return true;
    }

    //得到队头元素
    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return elem[front];
    }

    //得到队尾元素
    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        int index = (rear == 0) ? elem.length - 1 : rear - 1;
        return elem[index];
    }

    //队列是否为空
    public boolean isEmpty() {
        //return usedSize == 0;
        return rear == front;
    }

    //队列是否为满
    public boolean isFull() {
        //return usedSize == elem.lenth
        if ((rear + 1) % elem.length == front) {
            return true;
        }
        return false;
        /**
         * 或者可以直接return (rear + 1) % elem.length == front);
         */
    }
}